import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';
import 'package:www.znpigai.teacher/home_page/subject_tab_component/item/state.dart';
import 'package:www.znpigai.teacher/utils/util.dart';

import 'action.dart';

Widget buildView(
    SubjectState state, Dispatch dispatch, ViewService viewService) {
  List<Widget> typeList() {
    var result = List<Widget>();
    result.add(Text('作文主题',
        style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold)));
    state.articleTypeList.forEach((type) {
      result.add(
        Container(
          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
          decoration: new BoxDecoration(
            color: Color(0xFFD8E8FF),
            shape: BoxShape.rectangle,
            borderRadius: BorderRadius.circular(4.0),
          ),
          child: Text(
            GlobalState.types[type],
            style: TextStyle(color: Colors.blueAccent, fontSize: 12),
          ),
        ),
      );
    });
    return result;
  }

  List<Widget> themeList() {
    var result = List<Widget>();
    result.add(Text('写作题材',
        style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold)));
    state.themeList.forEach((theme) {
      result.add(
        Container(
          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
          decoration: new BoxDecoration(
            color: Color(0xFFD8E8FF),
            shape: BoxShape.rectangle,
            borderRadius: BorderRadius.circular(4.0),
          ),
          child: Text(
            GlobalState.themes[theme],
            style: TextStyle(color: Colors.blueAccent, fontSize: 12),
          ),
        ),
      );
    });
    return result;
  }

  return new Scaffold(
    appBar: new AppBar(
        centerTitle: true,
        elevation: 2.0,
        title: new Text(
          "题目详情",
          style: TextStyle(color: Colors.black54, fontSize: 18),
        )),
    body: SingleChildScrollView(
      child: Stack(
        children: <Widget>[
          Image.asset('assets/images/login_bg.png'),
          Column(
            children: <Widget>[
              SizedBox(height: 10),
              Card(
                  elevation: 4,
                  margin: EdgeInsets.fromLTRB(10, 4, 10, 10),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(5.0),
                  ),
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: EdgeInsets.all(20),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text('标题',
                                style: TextStyle(
                                    fontSize: 15, fontWeight: FontWeight.bold)),
                            new Divider(height: 1),
                            SizedBox(
                              width: double.infinity,
                              child: Text(state.title ?? '题目自拟'),
                            ),
                            SizedBox(height: 20),
                            Text('写作要求',
                                style: TextStyle(
                                    fontSize: 15, fontWeight: FontWeight.bold)),
                            new Divider(height: 1),
                            Container(
                              width: double.infinity,
                              constraints: BoxConstraints(minHeight: 160.0),
                              child: Text(Util.plainText(state.demand)),
                            ),
                            SizedBox(height: 20),
                            Wrap(
                                spacing: 10,
                                runSpacing: 10,
                                children: typeList()),
                            SizedBox(height: 20),
                            Wrap(
                                spacing: 10,
                                runSpacing: 10,
                                children: themeList()),
                          ],
                        ),
                      ),
                      Container(
                        height: 5,
                        decoration: BoxDecoration(
                          color: Colors.blue,
                          borderRadius: BorderRadius.only(
                              bottomLeft: Radius.circular(5),
                              bottomRight: Radius.circular(5)),
                        ),
                      ),
                    ],
                  )),
              SizedBox(height: 60),
            ],
          ),
        ],
      ),
    ),
    bottomSheet: Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        SizedBox(
            width: 120,
            child: FlatButton(
              color: Colors.blue,
              textColor: Colors.white,
              child: Text(state.self ? '修改题目' : '存入我的题库'),
              shape: RoundedRectangleBorder(
                  side: BorderSide(
                    color: Colors.white,
                    width: 0,
                  ),
                  borderRadius: BorderRadius.circular(20)),
              onPressed: () {
                if (state.self) {
                  dispatch(SubjectActionCreator.onEdit());
                } else {
                  dispatch(SubjectActionCreator.onSave());
                }
              },
            )),
        SizedBox(
          width: 120,
          child: FlatButton(
            padding: EdgeInsets.symmetric(horizontal: 30),
            color: Colors.blue,
            textColor: Colors.white,
            child: Text('布置作业'),
            shape: RoundedRectangleBorder(
                side: BorderSide(
                  color: Colors.white,
                  width: 0,
                ),
                borderRadius: BorderRadius.circular(20)),
            onPressed: () {
              dispatch(SubjectActionCreator.onPost());
            },
          ),
        ),
      ],
    ),
  );
}
